package io.hxci.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.hxci.modules.sys.dao.SysUserDeptDao;
import io.hxci.modules.sys.entity.SysDeptEntity;
import io.hxci.modules.sys.entity.SysUserDeptEntity;
import io.hxci.modules.sys.service.SysUserDeptService;

import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 用户与角色对应关系
 *
 */
@Service("sysUserDeptService")
public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptDao, SysUserDeptEntity> implements SysUserDeptService {
	@Override
	public void saveOrUpdate(Long userId, List<Long> deptIdList) {
		//先删除用户与角色关系
		this.remove(new QueryWrapper<SysUserDeptEntity>().eq("user_id", userId));

		if(deptIdList == null || deptIdList.size() == 0){
			return ;
		}
		
		//保存用户与部门三关系
		for(Long deptId : deptIdList){
			SysUserDeptEntity sysUserDeptEntity = new SysUserDeptEntity();
			sysUserDeptEntity.setUserId(userId);
			sysUserDeptEntity.setDeptId(deptId);

			this.save(sysUserDeptEntity);
		}

	}


	@Override
	public int deleteByUser(Long[] userIds){
		return baseMapper.deleteByUser(userIds);
	}

	@Override
	public List<SysDeptEntity> queryDeptList(Long userId) {
		// TODO Auto-generated method stub
		return baseMapper.queryDeptList(userId);
	}
}
